package com.yh.serviceImpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yh.bean.BuyGoods;
import com.yh.bean.CollectDetail;
import com.yh.bean.Game;
import com.yh.bean.GameClass;
import com.yh.bean.GameZone;
import com.yh.bean.Game_GameZone;
import com.yh.bean.Game_GameZone_GoodsClass;
import com.yh.bean.Goods;
import com.yh.bean.GoodsClass;
import com.yh.bean.Inorder;
import com.yh.bean.User;
import com.yh.dao.UserCoreDao;
import com.yh.service.UserCoreService;

@Service
@Transactional
public class UserCoreServiceImpl implements UserCoreService {

	@Autowired
	private UserCoreDao userDao;
	
	
	@Override
	public double addUmoney(Map<String, Object> map) {
		int num=userDao.addUmoney(map);
		if(num>0){
			double umoney=userDao.queryUmoney((int) map.get("uid"));
			return umoney;       //成功返回当前金额
		} 
		return -1;               //失败用-1返回表示             
	}


	@Override
	public User queryUserInfo(int uid) {
		User user=userDao.queryUserInfo(uid);
		return user;
	}


	@Override
	public boolean sign(int uid) {
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String strDate=sdf.format(date);
		String signDate=userDao.querySignDate(uid).getSignDate();
		System.out.println(strDate);
		if(!strDate.equals(signDate)){
			User user=new User();
			user.setSignDate(strDate);
			user.setUid(uid);
			int count=userDao.addSignDate(user);
			Map<String,Object> map=new HashMap<>();
			map.put("uid",user.getUid());
			map.put("integral", 10);                    //固定值 10分积分
			int count1=userDao.addIntegral(map);
			if(count!=0 && count1!=0){
				return true;
			}
		}
		return false;
	}


	@Override
	public boolean updateUserInfo(User user) {
		System.out.println("name:"+user.getUname()+"sex"+user.getSex()+"uremake:"+user.getUremake()+"photo:"+user.getPhoto());
		int count=userDao.updateUserInfo(user);
		System.out.println("************************count:"+count);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public boolean updateUserPassword(User user) {
		int count=userDao.updateUserPassword(user);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public boolean updateUserPayPassword(User user) {
		int count=userDao.updateUserPayPassword(user);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public List<Goods> queryGoods(Goods goods) {
		List<Goods> goodsList=userDao.queryGoods(goods);
		return goodsList;
	}


	@Override
	public boolean deleteGoods(String[] strArr) {
		int count=userDao.deleteGoods(strArr);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public List<GameClass> queryGameClass() {
		
		return userDao.queryGameClass();
	}


	@Override
	public List<Game> queryGame(int gcId) {
		
		return userDao.queryGame(gcId);
	}


	@Override
	public List<GameZone> queryGameZone(int gameId) {
		
		return userDao.queryGameZone(gameId);
	}


	@Override
	public int queryGame_GameZoneId(Game_GameZone ggz) {
		
		return userDao.queryGame_GameZoneId(ggz);
	}


	@Override
	public List<GoodsClass> queryGoodsClass(int g_gz_id) {
		
		return userDao.queryGoodsClass(g_gz_id);
	}


	@Override
	public boolean addGoods(Map<String, Object> map) {
		int count=userDao.addGoods(map);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public List<BuyGoods> queryBuyGoods(BuyGoods bg) {
		List<BuyGoods> bgoodsList=userDao.queryBuyGoods(bg);
		return bgoodsList;
	}


	@Override
	public List<Inorder> queryInorder(Inorder inorder) {
		List<Inorder> inorderList=userDao.queryInorder(inorder);
		return inorderList;
	}


	@Override
	public List<CollectDetail> queryCollectDetail(int uid) {
		List<CollectDetail> collList=userDao.queryCollectDetail(uid);
		return collList;
	}


	@Override
	public boolean deltecollectDetail(int cdId) {
		int count=userDao.deltecollectDetail(cdId);
		if(count>0){
			return true;
		}
		return false;
	}

	@Override
	public List<Goods> queryGoodsByBrowseRecords(int uid) {
		List<Goods> goodsList=userDao.queryGoodsByBrowseRecords(uid);
		return goodsList;
	}


	@Override
	public boolean addGameClass(String gcName) {
		int count=userDao.addGameClass(gcName);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public boolean addGame(Game game) {
		int count=userDao.addGame(game);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public boolean addGameZone(GameZone gameZone) {
		int count=userDao.addGameZone(gameZone);
		if(count>0){
			System.out.println("***************gzId="+gameZone.getGzId());
			return true;
		}
		return false;
	}


	@Override
	public boolean addGame_GameZone(Game_GameZone ggz) {
		int count=userDao.addGame_GameZone(ggz);
		if(count>0){
			return true;
		}
		return false;
	}


	@Override
	public Game_GameZone queryGame_GameZoneIdToBean(Game_GameZone ggz) {
		Game_GameZone reggz=userDao.queryGame_GameZoneIdToBean(ggz);
		return reggz;
	}


	@Override
	public boolean addGoodsClass(Map<String,Object> map) {
		GoodsClass gc=(GoodsClass) map.get("goodsClass");
		int count=userDao.addGoodsClass(gc);
		int gcId=gc.getGcId();
		Game_GameZone_GoodsClass ggg=(Game_GameZone_GoodsClass) map.get("ggg");
		ggg.setGc_id(gcId);
		int count2=userDao.addGame_GameZone_GoodsClass(ggg);
		if(count>0 && count2>0){
			return true;
		}
		return false;
	}

}
